package com.lishe.lishe.lishe.module.myorder.presenter;

import com.lishe.base.common.config.Constants;
import com.lishe.base.mvp.presenter.BaseMvpPresenter;
import com.lishe.lishe.lishe.common.Globals;
import com.lishe.lishe.lishe.module.myorder.bean.OrderListResponse;
import com.lishe.lishe.net.BaseProtocal;
import com.lishe.lishe.net.ResultListener;

/**
 * 标    题：订单列表presenter
 * 功能描述：
 * 作    者：zouxx
 * 创建时间：2018/8/21
 */

public class OrderListPresenter extends BaseMvpPresenter<OrderListContract.OrderListView> {

    private OrderListContract.OrderListModule module;

    public OrderListPresenter() {
        module = new OrderListContract.OrderListModule();
    }

    public void getOrderList(int page, String status) {
        if (getMvpView() != null)
            getMvpView().onLoading("加载中...");
        module.getOrderList(Globals.getToken(), status, String.valueOf(page), "10", new ResultListener() {
            @Override
            public void onSuccess(BaseProtocal mBaseProtocal) {
                if (getMvpView() != null)
                    getMvpView().getOrderList((OrderListResponse) mBaseProtocal);
            }

            @Override
            public void onFail(int errcode, String msg) {
                if (getMvpView() != null)
                    getMvpView().onRequestFailure(Constants.NEED_CHANGE_UI_TYPE, errcode, msg);
            }

            @Override
            public void onError(Throwable e) {
                if (getMvpView() != null)
                    getMvpView().onRequestFailure(Constants.NEED_CHANGE_UI_TYPE, 400, "网络异常");
            }
        });
    }

    public void confirmOrder(String paymentId) {
        if (getMvpView() != null)
            getMvpView().onLoading("");
        module.confirmOrder(Globals.getToken(), paymentId, new ResultListener() {
            @Override
            public void onSuccess(BaseProtocal mBaseProtocal) {
                if (getMvpView() != null)
                    getMvpView().confirmOrder(mBaseProtocal);
            }

            @Override
            public void onFail(int errcode, String msg) {
                if (getMvpView() != null)
                    getMvpView().onRequestFailure(Constants.UNNEED_CHANGE_UI_TYPE, errcode, msg);
            }

            @Override
            public void onError(Throwable e) {
                if (getMvpView() != null)
                    getMvpView().onRequestFailure(Constants.UNNEED_CHANGE_UI_TYPE, 400, "网络异常");
            }
        });
    }

    public void cancelOrder(String paymentId) {
        if (getMvpView() != null)
            getMvpView().onLoading("");
        module.cancelOrder(Globals.getToken(), paymentId, new ResultListener() {
            @Override
            public void onSuccess(BaseProtocal mBaseProtocal) {
                if (getMvpView() != null)
                    getMvpView().cancelOrder(mBaseProtocal);
            }

            @Override
            public void onFail(int errcode, String msg) {
                if (getMvpView() != null)
                    getMvpView().onRequestFailure(Constants.UNNEED_CHANGE_UI_TYPE, errcode, msg);
            }

            @Override
            public void onError(Throwable e) {
                if (getMvpView() != null)
                    getMvpView().onRequestFailure(Constants.UNNEED_CHANGE_UI_TYPE, 400, "网络异常");
            }
        });
    }
}
